package com.shiguiwu.springmybatis.spring.ioc;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @description: ioc容器
 * @author: stone
 * @date: Created by 2021/3/8 15:50
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.ioc
 */
public class ApplicationContextTests {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/ioc2.xml");

//        SpringHello bean = applicationContext.getBean(SpringHello.class);
//        bean.say();
//        System.out.println(bean);

        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            //获取bean的别名
            String[] aliases = applicationContext.getAliases(beanDefinitionName);
            System.out.println(String.format("beanName:%s,别名:[%s]", beanDefinitionName, String.join(",", aliases)));
        }

        //使用别名获取bean
        SpringHello bean = (SpringHello) applicationContext.getBean("hello5_1");
        bean.say();
        System.out.println(bean);
    }
}
